<?php
namespace Home\Model;
use Think\Model\RelationModel;
class UserDomainsModel extends RelationModel 
{
	
    protected $_link = array(
        'DomainType'=>array(
            'mapping_type'=> self::BELONGS_TO,
            'mapping_name'=> 'domainType',
            'class_name'=> 'DomainType',
            'foreign_key'=>'domain_typeid'
        )
    );
	
	
	
	/**
	 * 条件查询用户域名
	 * @param  $uid 用户uid
	 * @param  $check 审核状态，如果为null，则审核通过为前提
	 * @param  $status 约束条件，可以为 trans_status，is_mortage，is_lend
	 * @param  $statusField 对应约束条件字段
	 * @return mixed|boolean|string|NULL|unknown|object
	 */
	public function get_domains($uid,$check,$status,$statusField)
	{
		$condition_domain["uid"] = $uid;
		if(null == $check && null == $status){
		    $domain_list = $this->field(true)->where($condition_domain)->select();
		    return $domain_list;
		}else {
		    if(null == $check){
		        $condition_domain["check_status"] = 3;
		    }else {
		        $condition_domain["check_status"] = $check;
		    };
		    if(null != $status){
		        $condition_domain[$statusField] = $status;
		    };
		    $domain_list = $this->relation(true)->field(true)->where($condition_domain)->select();
		    return $domain_list;
		};
	}
	/**
	 * 条件查询用户域名数量
	 * @param  $uid 用户uid
	 * @param  $check 审核状态，如果为null，则审核通过为前提
	 * @param  $status 约束条件，可以为 trans_status，is_mortage，is_lend
	 * @param  $statusField 对应约束条件字段
	 * @return mixed|boolean|string|NULL|unknown|object
	 */
	public function get_domains_count($uid,$check,$status,$statusField)
	{
	    $condition_domain["uid"] = $uid;
	    if(null == $check && null == $status){
	        $count = $this->field(true)->where($condition_domain)->count();
	        return $count;
	    }else {
	        if(null == $check){
	            $condition_domain["check_status"] = 3;
	        }else {
	            $condition_domain["check_status"] = $check;
	        };
	        if(null != $status){
	            $condition_domain[$statusField] = $status;
	        };
	        return $this->field(true)->where($condition_domain)->count();
	    };
	}
}
?>